import { Entity, Column, PrimaryGeneratedColumn, OneToMany , ManyToOne, JoinColumn} from 'typeorm';
import { ApiProperty} from '@nestjs/swagger';
import { Goods } from './goods.entity';
import { IsOptional } from 'class-validator';

@Entity()
export class Category {
  @PrimaryGeneratedColumn()
  id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 90 })
  name: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 ,select: false})
  keywords: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int', width: 10})
  parent_id: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  sort_order: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1,select: false})
  show_index: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'tinyint', width: 1})
  is_show: number;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  front_desc: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  front_name: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 ,select: false})
  banner_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  icon_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  img_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 , select: false})
  wap_banner_url: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'varchar' ,length: 255 })
  level: string;

  @IsOptional()
  @ApiProperty()
  @Column({type: 'int' ,width: 11 ,select: false})
  type: number;

  @IsOptional()
  @ApiProperty()
  @OneToMany(type => Category, category => category.parent)
  children: Category[];

  @ManyToOne(type => Category, category => category.children)
  @JoinColumn({
    name: 'parent_id',
  })
  parent: Category;

  @OneToMany(type => Goods, goods => goods.category)
  goods: Goods[];

}
